*===============================================================================
*=== FILE 10 --- FOR-SALE CROSS-SECTIONAL AWARENESS PLOT
*===============================================================================
clear
set more off
cap ssc install spmap

cap cd ""


* following package is required:
* cap ssc install spmap


foreach state in FL NJ SC NC {
*===============================================================================
*=== CROSS-SECTIONAL PLOT
*===============================================================================
	* continue with preprocessed, real, full data
	* no confidentiality issues here
	use "../data/preprocessed/actual/zipcode_index", clear
	keep if state == "`state'"
	
	rename postalcode ZCTA5CE10
	
	merge 1:1 ZCTA5CE10 using "../data/actual/usdb", nogen keep(3)

	format index %4.2f
	
	spmap index using "../data/actual/uscoord.dta", id(id) ///
		fcolor(Blues) osize(thin) ocolor(gs3) ///
		clmethod(custom) clbreaks(.00 .01 .02 .03 .04 1) ///
		title("Cross-Sectional Index, `state'") ///
		legtitle("Attention Index") ///
		caption("{it:White areas have insufficient observations}", size(small))

	cap graph export "../replication output/`state'_index_map.png", width(2000) replace
	graph export "../replication output/`state'_index_map.pdf",  replace
	
	
*===============================================================================
*=== TIME-SERIES PLOT
*===============================================================================
	* first determine counties affected by 6ft water level rise
	cap use "../replication output\transaction_regression_data", replace
	cap collapse (max) uw6ft, by(postalcode)
	cap destring postalcode, replace
	cap save "../replication output\uw6ft_by_postal", replace
	
	* continue with real data
	use "../data/preprocessed/actual/zipcode_index_quarterly", clear
	keep if state == "`state'"
	
	rename postal postalcode
	* continue with real, preprocessed uw6ft by postal
	merge m:1 postalcode using "../data/preprocessed/actual/uw6ft_by_postal", nogen keep(3)
	
	collapse (mean) index, by(listing_quarter uw6ft)
	
	rename index index_uw6ft
	bys listing_quarter: egen index_all = mean(index)
	
	keep if uw6ft == 1
	
	tsset listing_quarter
	tsline index_all index_uw6ft, ///
		title("Climate Attention Index for `state'") xtitle("Period") ///
		legend(label(1 "State Level") ///
		label(2 "Zip Codes w/ Properties in Flood and Non-Flood Zones") ///
		size(small)) graphregion(color(white)) ///
		lcolor("68 119 170" "102 204 238") lpattern(solid dash) lwidth(thick thick) ///
		xlabel(,grid  ) ylabel(,grid ) plotregion(lcolor(black))

	cap graph export "../replication output/`state'_index_series.png", width(2000) replace
	graph export "../replication output/`state'_index_series.pdf", replace
}











